package org.jeecg.common.support;

import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysDepartModel;

/**
 * @author leikai
 * @version 1.0
 * @description: ThreadLoca工具类
 * @date 2022/01/08/0008 12:41
 */
public class ThreadLocalHolder {
    /**
     * userThreadLocal
     */
    private static ThreadLocal<LoginUser> userThreadLocal = new ThreadLocal<LoginUser>();

    /**
     * tokenThreadLocal
     */
    private static ThreadLocal<String> tokenThreadLocal = new ThreadLocal<String>();

    private static ThreadLocal<SysDepartModel> departThreadLocal = new ThreadLocal<SysDepartModel>();

    /**
     *
     */
    public static void setToken(String token) {
        tokenThreadLocal.set(token);
    }

    public static String getToken() {
        return tokenThreadLocal.get();
    }

    public static void setUser(LoginUser user) {
        userThreadLocal.set(user);
    }

    public static void setDepart(SysDepartModel depart) {
        departThreadLocal.set(depart);
    }

    public static SysDepartModel getDepart() {
        SysDepartModel sysDepartModel = departThreadLocal.get();
        if (null != sysDepartModel) {
            return sysDepartModel;
        }
        return null;
    }

    public static LoginUser getLoginUser() {
        LoginUser loginUser = userThreadLocal.get();
        if (null != loginUser) {
            return loginUser;
        }
        return null;
    }

    public String getLoginUserId() {
        LoginUser loginUser = userThreadLocal.get();
        if (null != loginUser) {
            return loginUser.getId();
        }
        return null;
    }

    public String getLoginUserName() {
        LoginUser loginUser = userThreadLocal.get();
        if (null != loginUser) {
            return loginUser.getUsername();
        }
        return null;
    }

    public String getLoginUserOrgCode() {
        LoginUser loginUser = userThreadLocal.get();
        if (null != loginUser) {
            return loginUser.getOrgCode();
        }
        return null;
    }
}
